package view;

import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import util.MyTable;
import entities.Variable;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class TestWindow extends javax.swing.JFrame {
	private JPanel jPanel1;
	private JLabel lblStatus;
	private JScrollPane jScrollPane1;
	private JButton btnStart;
	private JButton btnStop;
	private JPanel jPanel3;
	private MyTable tblVars;
	private JProgressBar jProgressBar1;
	private JPanel jPanel2;
	private TableModel tblVarsModel;

	/**
	 * Auto-generated main method to display this JFrame
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				TestWindow inst = new TestWindow();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}

	public TestWindow() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			BorderLayout thisLayout = new BorderLayout();
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setTitle("i2M - Teste de Comunicação");
			getContentPane().setLayout(thisLayout);
			{
				jPanel1 = new JPanel();
				BorderLayout jPanel1Layout = new BorderLayout();
				getContentPane().add(jPanel1, BorderLayout.CENTER);
				jPanel1.setLayout(jPanel1Layout);
				{
					jScrollPane1 = new JScrollPane();
					jPanel1.add(jScrollPane1, BorderLayout.CENTER);
					{
						tblVarsModel = new DefaultTableModel(new String[][] {},
								new String[] { "Nome", "Endereço", "Status" });
						tblVars = new MyTable();
						jScrollPane1.setViewportView(tblVars);
						tblVars.setModel(tblVarsModel);
					}
				}
			}
			{
				jPanel2 = new JPanel();
				getContentPane().add(jPanel2, BorderLayout.SOUTH);
				jPanel2.setPreferredSize(new java.awt.Dimension(392, 30));
				jPanel2.setLayout(null);
				{
					jProgressBar1 = new JProgressBar();
					jPanel2.add(jProgressBar1);
					jProgressBar1.setBounds(232, 7, 148, 14);
					jProgressBar1.setValue(50);
					jProgressBar1.setStringPainted(true);
				}
				{
					lblStatus = new JLabel();
					jPanel2.add(lblStatus);
					lblStatus.setText("Testing...");
					lblStatus.setBounds(12, 7, 68, 14);
				}
			}
			{
				jPanel3 = new JPanel();
				jPanel3.setLayout(null);
				getContentPane().add(jPanel3, BorderLayout.NORTH);
				jPanel3.setPreferredSize(new java.awt.Dimension(392, 38));
				{
					btnStart = new JButton();
					jPanel3.add(btnStart);
					btnStart.setText("Iniciar");
					btnStart.setLayout(null);
					btnStart.setBounds(12, 10, 112, 21);
				}
				{
					btnStop = new JButton();
					jPanel3.add(btnStop);
					btnStop.setText("Parar");
					btnStop.setLayout(null);
					btnStop.setBounds(142, 10, 112, 21);
				}
			}
			pack();
			setSize(400, 300);
			this.setLocationRelativeTo(null);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void setTblVariaveis() {
		// TODO PESQUISA POR TODAS AS VARIAVEIS QUE EXISTEM
		// TODO ATUALIZAR O STATUS QUANDO ESTIVERMOS TESTANDO
		List<Variable> list = new ArrayList<Variable>();
		Variable variable;
		String[][] data = new String[list.size()][3];
		for (int i = 0; i < list.size(); i++) {
			variable = list.get(i);
			data[i][0] = variable.getName();
			data[i][1] = String.valueOf(variable.getAddress());
			data[i][2] = "";
		}
		tblVarsModel = new DefaultTableModel(data, new String[] { "Nome",
				"Endereço", "Status" });
		tblVars.setModel(tblVarsModel);
		tblVars.updateUI();
	}
}
